﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Activation;
using System.Collections;
using System.Data;
using System.Text.RegularExpressions;
using System.IO;
using System.Web.Hosting;
using System.ServiceModel.Web;
using System.Net.Mail;
using System.Net;

namespace elr_tracking_web.Services
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [DataContractFormat]
    public class User : IUser
    {
        /// <summary>
        /// Servicio para insertar un Usuario
        /// </summary>
        /// <param name="ID_USER"></param>
        /// <param name="USER_NAME"></param>
        /// <param name="USER_MAIL"></param>
        /// <param name="PASSWORD"></param>
        /// <param name="DEFAULT_PAGE"></param>
        /// <returns></returns>
        public elr_tracking_bal.UpsertStateMsg InsertUser(string USER_NAME, string USER_MAIL,
                                                    string PASSWORD, string DEFAULT_PAGE)
        {
            elr_tracking_bal.UpsertStateMsg insertUser;
            elr_tracking_bal.APP_USER user;
            user = new elr_tracking_bal.APP_USER(USER_NAME, USER_MAIL, PASSWORD, DEFAULT_PAGE);
            insertUser = elr_tracking_bal.APP_USER.InsertUser(user);
            return insertUser;
        }
        /// <summary>
        /// Servicio para borrar Usuarios
        /// </summary>
        /// <param name="ID_USER"></param>
        /// <returns></returns>
        public elr_tracking_bal.DeleteStateMsg DeleteUser(string ID_USER)
        {
            string[] _ID_USER = ID_USER.Split(',');
            elr_tracking_bal.DeleteStateMsg delete;
            delete = elr_tracking_bal.APP_USER.DeleteUser(_ID_USER);
            return delete;
        }
        /// <summary>
        /// Servicio para actualizae un Usuario
        /// </summary>
        /// <param name="ID_USER"></param>
        /// <param name="USER_NAME"></param>
        /// <param name="USER_MAIL"></param>
        /// <param name="PASSWORD"></param>
        /// <param name="DEFAULT_PAGE"></param>
        /// <returns></returns>
        public elr_tracking_bal.UpsertStateMsg UpdateUser(int ID_USER, string USER_NAME, string USER_MAIL,
                                                    string PASSWORD, string DEFAULT_PAGE)
        {
            elr_tracking_bal.UpsertStateMsg updateUser;
            elr_tracking_bal.APP_USER user;
            user = new elr_tracking_bal.APP_USER(ID_USER, USER_NAME, USER_MAIL, PASSWORD, DEFAULT_PAGE);
            updateUser = elr_tracking_bal.APP_USER.UpdateUser(user);
            return updateUser;
        }
        /// <summary>
        /// Servicio para obtener un Usuario
        /// </summary>
        /// <param name="ID_USER"></param>
        /// <returns></returns>
        public elr_tracking_bal.APP_USER GetOneUser(int ID_USER)
        {
            elr_tracking_bal.APP_USER user;
            user = elr_tracking_bal.APP_USER.GetOneUser(ID_USER);
            return user;    
        }
        /// <summary>
        /// Servicio para obtener la lista de Usuarios
        /// </summary>
        /// <param name="ID_USER"></param>
        /// <returns></returns>
        public List<elr_tracking_bal.APP_USER> GetDataListUser(string ID_USER)
        {
            List<elr_tracking_bal.APP_USER> user;
            string[] _ID_USER;
            if (ID_USER == null)
            {
                user = elr_tracking_bal.APP_USER.GetDataListUser(null);
                return user;
            }
            else {
                _ID_USER = ID_USER.Split(',');
                user = elr_tracking_bal.APP_USER.GetDataListUser(_ID_USER);
                return user;
            }
        }
        /// <summary>
        /// Servicio para insertar un Rol
        /// </summary>
        /// <param name="ID_ROL"></param>
        /// <param name="ROL_NAME"></param>
        /// <param name="ROL_PRIORITY"></param>
        /// <returns></returns>
        public elr_tracking_bal.UpsertStateMsg InsertRol(string ROL_NAME, int ROL_PRIORITY)
        {
            elr_tracking_bal.UpsertStateMsg insertRol;
            elr_tracking_bal.APP_ROL rol;
            rol = new elr_tracking_bal.APP_ROL(ROL_NAME, ROL_PRIORITY);
            insertRol = elr_tracking_bal.APP_ROL.InsertRol(rol);
            return insertRol;
        }
        /// <summary>
        /// Servicio para borrar Roles
        /// </summary>
        /// <param name="ID_ROL"></param>
        /// <returns></returns>
        public elr_tracking_bal.DeleteStateMsg DeleteRol(string ID_ROL)
        {
            string[] _ID_ROL = ID_ROL.Split(',');
            elr_tracking_bal.DeleteStateMsg delete;
            delete = elr_tracking_bal.APP_ROL.DeleteRol(_ID_ROL);
            return delete;
        }
        /// <summary>
        /// Servicio para actualizar un Rol
        /// </summary>
        /// <param name="ID_ROL"></param>
        /// <param name="ROL_NAME"></param>
        /// <param name="ROL_PRIORITY"></param>
        /// <returns></returns>
        public elr_tracking_bal.UpsertStateMsg UpdateRol(int ID_ROL, string ROL_NAME, int ROL_PRIORITY)
        {
            elr_tracking_bal.UpsertStateMsg updateRol;
            elr_tracking_bal.APP_ROL rol;
            rol = new elr_tracking_bal.APP_ROL(ID_ROL, ROL_NAME, ROL_PRIORITY);
            updateRol = elr_tracking_bal.APP_ROL.UpdateRol(rol);
            return updateRol;
        }
        /// <summary>
        /// Servicio para obtener un rol
        /// </summary>
        /// <param name="ID_ROL"></param>
        /// <returns></returns>
        public elr_tracking_bal.APP_ROL GetOneRol(int ID_ROL)
        {
            elr_tracking_bal.APP_ROL rol;
            rol = elr_tracking_bal.APP_ROL.GetOneRol(ID_ROL);
            return rol;
        }
        /// <summary>
        /// Servicio para obteneres todos los roles
        /// </summary>
        /// <param name="ID_ROL"></param>
        /// <returns></returns>
        public List<elr_tracking_bal.APP_ROL> GetDataListRol(string ID_ROL)
        {
            List<elr_tracking_bal.APP_ROL> rol;
            string[] _ID_ROL;
            if (ID_ROL == null)
            {
                rol = elr_tracking_bal.APP_ROL.GetDataListRol(null);
                return rol;
            }
            else
            {
                _ID_ROL = ID_ROL.Split(',');
                rol = elr_tracking_bal.APP_ROL.GetDataListRol(_ID_ROL);
                return rol;
            }
        }
        /// <summary>
        /// Servicio para obtener la información de las columnas
        /// </summary>
        /// <param name="NAME_TABLE"></param>
        /// <returns></returns>
        public List<elr_tracking_bal.INFORMATION_COLUMNS> GetInformationColumns(string NAME_TABLE)
        {
            List<elr_tracking_bal.INFORMATION_COLUMNS> info;
            string _NAME_TABLE;
            if (NAME_TABLE == null)
            {
                info = elr_tracking_bal.INFORMATION_COLUMNS.GetInformationColumns(null);
                return info;
            }
            else
            {
                info = elr_tracking_bal.INFORMATION_COLUMNS.GetInformationColumns(NAME_TABLE);
                return info;
            }
        }
        /// <summary>
        /// Servicio para crear la relación entre usuario y roles
        /// </summary>
        /// <param name="ID_USER"></param>
        /// <param name="ROLES"></param>
        /// <returns></returns>
        public elr_tracking_bal.UpsertStateMsg insertRelUserRol(int ID_USER, string ROLES)
        {
            elr_tracking_bal.UpsertStateMsg insertRel;
            elr_tracking_bal.APP_USER rel;
            //rel = new elr_tracking_web.APP_USER(ID_USER, ROLES);
            insertRel = elr_tracking_bal.APP_USER.insertRelUserRol(ID_USER, ROLES);
            return insertRel;
        }
        /// <summary>
        /// Servicio para obtener la lista de roles con check
        /// </summary>
        /// <param name="ID_USER"></param>
        /// <returns></returns>
        public List<elr_tracking_bal.APP_USER> GetListRolChecked(string ID_USER)
        {
            List<elr_tracking_bal.APP_USER> rol;
            rol = elr_tracking_bal.APP_USER.GetListRolChecked(ID_USER);
                return rol;
            
        }
        /// <summary>
        /// Servicio para validar inicio de sesión de usuario
        /// </summary>
        /// <param name="ID_USER"></param>
        /// <returns></returns>
        public elr_tracking_bal.APP_USER ValidateUser(string USER_MAIL, string PASSWORD)
        {
            elr_tracking_bal.APP_USER user;
            user = elr_tracking_bal.APP_USER.ValidateUser(USER_MAIL, PASSWORD);
            return user;
        }
        /// <summary>
        /// Servicio que cambia el estado de la columna FLAG a 1
        /// </summary>
        /// <param name="FLAG"></param>
        /// <returns></returns>
        public string UpdateFlagRecoverUserPassword(string USER_MAIL)
        {
            string re="";
            re = elr_tracking_bal.APP_USER.UpdateFlagRecoverUserPassword(USER_MAIL);
            return re;
        }
        /// <summary>
        /// Servicio para la activación del Usuario
        /// </summary>
        /// <param name="codigo"></param>
        /// <returns></returns>
        public string UpdateflagActivacion(string codigo)
        {
            string re = "";
            re = elr_tracking_bal.APP_USER.UpdateflagActivacion(codigo);
            return re;
        }
        /// <summary>
        /// Servicio para obtener el correo del Usuario 
        /// </summary>
        /// <param name="codigo"></param>
        /// <returns></returns>
        public string GetOneMail(string codigo)
        {
            string re = "";
            re = elr_tracking_bal.APP_USER.GetOneMail(codigo);
            return re;
        }
    }
}
    